package com.chushouya.controller.open;


import com.chushouya.common.annotations.AuthSkip;
import com.chushouya.common.constant.ServiceType;
import com.chushouya.order.service.admin.AlipayNotifyTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Map;

import static com.chushouya.common.util.OrderUtil.requestToMap;


/**
 * 支付宝网关
 */
@RestController
@RequestMapping(ServiceType.OPEN_API + "/alipayNotify")
@Slf4j

public class AlipayNotifyController {

    @Resource
    private AlipayNotifyTypeService alipayNotifyTypeService;

    /**
     * 支付宝网关 https://test-api.suhuishou.com/suhuishou-order/open-api/alipayNotify/index
     */
    @PostMapping("/index")
    @AuthSkip
    public String alipayNotify(HttpServletRequest request) {
        log.info("支付宝订单支付回调, {}", request.getParameterMap());
        Map<String, String> params = requestToMap(request);
        log.info("支付宝订单解析, {}", params);
        alipayNotifyTypeService.getResult(params);
        return "success";
    }
}
